import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2022-03-24
 * Time: 19:12
 */
public class Demo01 {
    //打印菱形
    public static void main(String[] args) {
        int n = 13;
        int i,j;
        for (i = 0; i < n; i++) {
            if(i <= n/2) {
                for (j = 0; j < n; j++) {
                    if( j< n/2 -i) {
                        System.out.print("  ");
                    } else if (j>=n/2-i && j<=n/2+i) {
                        System.out.print("* ");
                    }
                }
            } else {
                for (j = 0; j < n; j++) {
                    if( j < i-n/2) {
                        System.out.print("  ");
                    } else if (j >= i- n/2 && j<= (3*n)/2 - i -1) {
                        System.out.print("* ");
                    }
                }
            }
            System.out.println();
        }
    }
    //只出现一次的数字
    public static void main4(String[] args) {
        int []arr = {4,1,2,1,2,4,5,5,6,6,7};
        int ret =0 ;
        for (int i = 0; i < arr.length; i++) {
            ret ^=  arr[i] ;
        }
        System.out.println(ret);
    }
    //冒泡排序
    public static void main3(String[] args) {
        int []arr = {5,1,2,3,4};
        boolean flag = true ;
        for (int i = 0; i < arr.length - 1; i++) {
            flag = true;
            for (int j = 0; j < arr.length - i - 1; j++) {
                int temp = 0;
                if( arr[j] > arr[j+1]) {
                    temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                    flag = false;
                }
            }
            if( flag == true) {
                break;
            }
        }
        System.out.println(Arrays.toString(arr));
    }
    //数组是否有序
    public static void main2(String[] args) {
        int []arr = {1,2,3,4,5,6};
        boolean flag = true;
        for(int i = 0;i < arr.length-1; i++) {
            if( arr[i] >arr[i+1]) {
                flag = false ;
            }
        }
        if( flag == true ) {
            System.out.println("递增");
        } else {
            System.out.println("不是递增");
        }
    }
    //二分查找
    public static void main1(String[] args) {
        int []arr = {1,2,3,4,5,6,7,8,9,10};
        int ret = search ( arr,1);
        if( ret == -1) {
            System.out.println( "找不到");
        } else {
            System.out.println("找到了，下标是：" + ret);
        }
    }
    public static int search (int []arr,int k) {
        int left = 0;
        int right = arr.length - 1;
        while( left <= right) {
            int mid = (left+right) / 2 ;
            if( arr[mid] < k ) {
                left = mid + 1;
            } else if ( arr[mid] > k) {
                right = mid -1;
            } else {
                return mid;
            }
        }
        return -1;
    }
}
